//
//  HMStatusModel.swift
//  CZBKWB31
//
//  Created by Linkon Y on 16/8/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMStatusModel: NSObject {

    // MARK: - 模型属性
    // 创建时间
    var created_at: String?
    // 微博ID
    var id: Int64  = 0
    // 微博信息内容
    var text: String?
    // 微博来源
    var source: String?
    // 用户模型
    var user: HMUserModel?
    //转发微博
    var retweeted_status:HMStatusModel?
    //配图
    var pic_urls:[HMPictureInfoModel]?
    // int	转发数
    var reposts_count: Int = 0
    // int	评论数
    var comments_count: Int = 0
    //int	表态数
    var attitudes_count: Int = 0
    
    
    init(dict:[String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    //重写setValue
    override func setValue(value: AnyObject?, forKey key: String) {
        //判断value 是否为nil 可否转成一个字典
       
        if key == "user"{
            guard let v = value as? [String: AnyObject] else{
            
                return
            }
            //手动给user赋值
            user = HMUserModel(dict:v)
         
        }else if key == "retweeted_status"{
            //判断value 是否为nil 可否转成一个字典
                guard let v = value as? [String: AnyObject] else{
                    return
                }
            //手动给retweeted_status赋值
            retweeted_status = HMStatusModel(dict:v)
        
        }else if key == "pic_urls"{
            //判断value 是否为nil 可否转成一个字典
            guard let v = value as? [[String: AnyObject]] else{
                return
            }
            //创建一个临时可变的数组
            var tempArr: [HMPictureInfoModel] = [HMPictureInfoModel]()
          //遍历数据
            for dic in v {
                
                let pic = HMPictureInfoModel(dict: dic)
                
                tempArr.append(pic)
            }
            //赋值
            pic_urls = tempArr
        
        }else{
           super.setValue(value, forKey: key)
        }
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
